/*
 * Copyright (c) 2019, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2019-08-26     sogwms       The first version
 */

#ifndef __SERVO_H__
#define __SERVO_H__

#include <aos/aos.h>
#include <devices/pwm.h>
#include <devices/driver.h>
#include <devices/devicelist.h>
#include "aos/cli.h"

// 20ms; 1.5ms; +-1ms
#define SERVO_PERIOD                    50.0//hz
#define SERVO_DEFAULT_PULSE_MAX         2.5//ms
#define SERVO_DEFAULT_PULSE_MIN         0.5//ms

typedef struct servo *servo_t;

struct servo
{
    rvm_dev_t               *pwmdev;
    int                     channel;
    float                   angle_maximum;
    float                   pluse_maximum;
    float                   pluse_minimum;
};

servo_t  servo_create(const char * pwm, int channel, float angle, unsigned int pluse_min, unsigned int pluse_max);
signed long servo_destroy(servo_t servo);
signed long servo_enable(servo_t servo);
signed long servo_disable(servo_t servo);
signed long servo_reset(servo_t servo);
signed long servo_set_angle(servo_t servo, float angle);

#endif //  __SERVO_H__
